package com.itheima.controller;


import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.dto.OrderDTO;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 预约
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody OrderDTO orderDTO) {
        try{
            orderService.submitOrder(orderDTO);

        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, e.getMessage());
        }

        return new Result(true, MessageConstant.ORDER_SUCCESS);
    }

    @GetMapping("/findById")
    public Result findById(Long id){

           Order order =  orderService.findById(id);
           if(order == null){
               return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
           }
         return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS,order);
    }

}
